home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_46 / dacdir.c next >
C/C++ Source or Header  |  1995-01-01  |  1KB  |  72 lines

  1. /* Output to SB DAC in single sample mode
  2.    (non-functional; no control over the playback rate)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dos.h>
  8. #include <conio.h>
  9. #include <io.h>
  10. #include <alloc.h>
  11.  
  12. #include "sb.h"
  13.  
  14. /* Read first 64000 bytes of a raw sample file and play the sample */
  15. void main(int argc, char *argv[])
  16. {
  17.     FILE *f;
  18.     signed char *raw;
  19.     unsigned sample_len;
  20.     register int i;
  21.  
  22.     if(argc != 2)
  23.     {
  24.     puts("Usage: dacdir sample_file");
  25.     exit(1);
  26.     }
  27.  
  28.     if(Sb_Get_Params())
  29.     {
  30.         puts("BLASTER environment variable not set.");
  31.         exit(1);
  32.     }
  33.  
  34.     if(Sb_Init())
  35.     {
  36.     printf("Could not find Soundblaster!\n");
  37.     exit(1);
  38.     }
  39.     printf("Found Soundblaster at %xh.\n",SbIOaddr);
  40.  
  41.     f = fopen(argv[1],"rb");
  42.     if(f == NULL)
  43.     {
  44.     printf("Could not open sample file %s\n",argv[1]);
  45.     }
  46.     sample_len = (unsigned)filelength(fileno(f));
  47.  
  48.     raw = (signed char *)malloc(sample_len);
  49.     fread(raw,1,sample_len,f);
  50.  
  51.     fclose(f);
  52.  
  53.     Sb_Voice(1);
  54.  
  55.     for(i = 0; i < sample_len; i++)
  56.     {
  57.         writedac(0x10);
  58.         writedac(raw[i]);
  59.  
  60.         while(inportb(SbIOaddr+DSP_DATA_AVAIL) & 0x80)
  61.         ;
  62.     }
  63.  
  64.     Sb_Voice(0);
  65.  
  66.     free(raw);
  67.  
  68.     Sb_Init();
  69.  
  70.     exit(0);
  71. }
  72.